package com.core.util;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.core.cache.Cache;

public class InitParameters extends HttpServlet {
	Logger logger = Logger.getLogger(DspUtil.Log4J);
	/**
	 * 
	 */
	private static final long serialVersionUID = 6002914967860309479L;

	public void init(ServletConfig c) throws ServletException {
		super.init(c);
		logger.debug("正在读取spring context信息.....");
		ServletContext servletContext = c.getServletContext();
		String path = this.getServletConfig().getServletContext().getRealPath("");
		logger.debug("realPath : "+path);
		DspUtil.setRealPath(path);
		ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
		logger.debug("读取完成.......");
		DspContext.setCtx(ctx);
		logger.debug("测试加载信息成功.....");
		
		logger.debug("加载缓存数据.....");
		this.initCache();
		logger.debug("完成加载数据.....");
	}
	
	/**
	 * 初始化需要缓存的数据
	 */
	public void initCache(){
		logger.info("初始化省，市，区数据......");
		Cache.getProvince();
		logger.info("完成省，市，区数据......");
		
		logger.info("正在加载公司资料.......");
		Cache.getCompany();
		logger.info("公司资料加载完成.......");
		
		logger.info("正在加载系统标签.......");
		Cache.getSelect();
		logger.info("系统标签加载完成.......");
		
		logger.debug("正在加载社保项目.......");
		Cache.getItemMap();
		logger.debug("社保项目加载完成.......");
	}

}
